import { configuration } from '../../config/webapi';
import View from '../View';
import event from '../../util/NotifierManager';
import {
    INDEX_BLASTFURNACE,
} from '../../util/constant';

/**
 * 图扑熔保炉
 *
 * @export
 * @class Index2dFurnace
 * @extends {View}
 */
export default class Index2dBlastFurnace extends View {

    constructor(view, main) {
        super(view, main);

        this.url = 'displays/tenant/OPCUAWebAPIss/Dev/高炉.json'; // 图扑高炉 2D+3D displays/tenant/OPCUAWebAPIss/高炉.json
        this.key = INDEX_BLASTFURNACE;

        this.tags = ['progress', 'blastfurnace_chart1', 'blastfurnace_chart1_l1', 'blastfurnace_chart1_l2', 'blastfurnace_chart2',
            'blastfurnace_chart3', 'blastfurnace_chart4', 'naviNode'];
        for (let i = 1; i <= 8; i++) {
            this.tags.push('blastfurnace_chart2_l' + i);
        }
        for (let i = 1; i <= 4; i++) {
            this.tags.push('blastfurnace_chart4_l' + i);
        }
        for (let i = 1; i <= 9; i++) {
            this.tags.push('energy' + i);
        }
        for (let i = 1; i <= 3; i++) {
            this.tags.push('yield' + i);
        }
        for (let i = 1; i <= 5; i++) {
            this.tags.push('condition' + i);
        }
        this.btnTags = [];
        this.tags = this.tags.concat(this.btnTags);

        this.tagMap = {
            blastfurnace_energy: [],
            blastfurnace_yield: [],
            blastfurnace_condition: [],

            blastfurnace_chart1_1: [],
            blastfurnace_chart1_2: [],

            blastfurnace_chart2_1: [],
            blastfurnace_chart2_2: [],
            blastfurnace_chart2_3: [],
            blastfurnace_chart2_4: [],
            blastfurnace_chart2_5: [],
            blastfurnace_chart2_6: [],
            blastfurnace_chart2_7: [],
            blastfurnace_chart2_8: [],

            blastfurnace_chart3_1: [],
            blastfurnace_chart3_2: [],
            blastfurnace_chart3_3: [],

            blastfurnace_chart4_1: [],
            blastfurnace_chart4_2: [],
            blastfurnace_chart4_3: [],
            blastfurnace_chart4_4: [],
        }

        window.index2dFurnace = this;
    }

    onPostDeserialize() {
        if (!ht.animationplayer.g2d) {
            ht.animationplayer.g2d = this.view;
            ht.animationplayer.player2d = new ht.animationplayer.blueprintplayer(view);
            ht.animationplayer.player2d.init();
        } else {
            ht.animationplayer.player2d.init(true);
        }

        this.getDatasByTag();
        this.progress.s('2d.visible', false);

        this.naviNode.a('onStateChange', (state) => {
            this.onStateChange(state);
        });

        this.startRefreshTask();
        this.readAll();
    }

    handleInteractive(e) {
        const { kind, data } = e;
        if (kind == 'doubleClickBackground') {
            return;
        }
        if (kind == 'clickData') {
            this.handleClickData(data);
        }

    }

    handleClickData(data) {
        // console.log(data);
    }

    /******************************* OPCUA BEGIN ******************************** */

    handleUpdateBooleanNode(tag, valueObj) {
    }

    handleUpdateNumberNode(tag, valueObj) {

    }

    /**
     *
     *
     * @param {*} tag tagMap中的tag
     * @param {*} valueObj .Value = [0.1,...], 数值范围是0~1之间的随机数
     * @memberof Index2dHeat
     */
    handleUpdateArrayNode(tag, valueObj) {
        // console.log('-----handleUpdateArrayNode-----', { tag, valueObj })

        switch (tag) {
            case 'blastfurnace_chart1_1':
                this.blastfurnace_chart1.a('lineData1', valueObj.Value);
                this.blastfurnace_chart1_l1.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart1_2':
                this.blastfurnace_chart1.a('lineData2', valueObj.Value);
                this.blastfurnace_chart1_l2.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart2_1':
                this.blastfurnace_chart2.a('lineData1', valueObj.Value);
                this.blastfurnace_chart2_l1.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart2_2':
                this.blastfurnace_chart2.a('lineData2', valueObj.Value);
                this.blastfurnace_chart2_l2.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart2_3':
                this.blastfurnace_chart2.a('lineData3', valueObj.Value);
                this.blastfurnace_chart2_l3.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart2_4':
                this.blastfurnace_chart2.a('lineData4', valueObj.Value);
                this.blastfurnace_chart2_l4.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart2_5':
                this.blastfurnace_chart2.a('lineData5', valueObj.Value);
                this.blastfurnace_chart2_l5.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart2_6':
                this.blastfurnace_chart2.a('lineData6', valueObj.Value);
                this.blastfurnace_chart2_l6.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart2_7':
                this.blastfurnace_chart2.a('lineData7', valueObj.Value);
                this.blastfurnace_chart2_l7.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart2_8':
                this.blastfurnace_chart2.a('lineData8', valueObj.Value);
                this.blastfurnace_chart2_l8.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart3_1':
                this.blastfurnace_chart3.a('lineData1', valueObj.Value);
                break;
            case 'blastfurnace_chart3_2':
                this.blastfurnace_chart3.a('lineData2', valueObj.Value);
                break;
            case 'blastfurnace_chart3_3':
                this.blastfurnace_chart3.a('lineData3', valueObj.Value);
                break;
            case 'blastfurnace_chart4_1':
                this.blastfurnace_chart4.a('lineData1', valueObj.Value);
                this.blastfurnace_chart4_l1.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart4_2':
                this.blastfurnace_chart4.a('lineData2', valueObj.Value);
                this.blastfurnace_chart4_l2.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart4_3':
                this.blastfurnace_chart4.a('lineData3', valueObj.Value);
                this.blastfurnace_chart4_l3.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_chart4_4':
                this.blastfurnace_chart4.a('lineData4', valueObj.Value);
                this.blastfurnace_chart4_l4.a('text2', valueObj.Value.at(-1));
                break;
            case 'blastfurnace_energy':
                valueObj.Value.forEach((v, i) => {
                    this['energy' + (i + 1)].a('value', v);
                });
                break;
            case 'blastfurnace_yield':
                valueObj.Value.forEach((v, i) => {
                    this['yield' + (i + 1)].a('value', v);
                });
                break;
            case 'blastfurnace_condition':
                valueObj.Value.forEach((v, i) => {
                    switch (i + 1) {
                        case 1:
                            v = (v * 100).toFixed(1);
                            break;
                        case 2:
                            v = (v * 1000).toFixed(0);
                            break;
                        case 3:
                            v = v.toFixed(2);
                            break;
                        case 4:
                            v = (v * 100).toFixed(1);
                            break;
                        case 5:
                            v = v.toFixed(2);
                            break;
                    }
                    this['condition' + (i + 1)].a('value', v);
                });
                break;
            default:
                break;
        }
    }



}
